﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Qiang.Geometry
{
    public class Point : Geometry, IPoint
    {

        #region 初始化

        /// <summary>
        /// 点
        /// </summary>
        public Point()
            : base()
        {
            _coordinates = new List<Coordinate>();
        }

        /// <summary>
        /// 点
        /// </summary>
        /// <param name="coordinate"></param>
        public Point(Coordinate coordinate)
            : base()
        {
            _coordinates = new List<Coordinate>();
            _coordinates.Add(coordinate);
        }

        #endregion



        #region IPoint成员

       
        /// <summary>
        /// 坐标
        /// </summary>
        public Coordinate Coordinate
        {
            get 
            {
                if (_coordinates == null) _coordinates = new List<Coordinate>();
                if (_coordinates.Count == 0) _coordinates.Add(new Coordinate());
                return _coordinates[0];
            }           
        }

        /// <summary>
        /// X
        /// </summary>
        public double X
        {
            get { return Coordinate.X; }
            set { _coordinates[0].X = value; }
        }

        /// <summary>
        /// Y
        /// </summary>
        public double Y
        {
            get { return Coordinate.Y; }
            set { _coordinates[0].Y = value; }
        }

        /// <summary>
        /// Z
        /// </summary>
        public double Z
        {
            get { return Coordinate.Z; }
            set { _coordinates[0].Z = value; }
        }

        /// <summary>
        /// M
        /// </summary>
        public double M
        {
            get { return Coordinate.M; }
            set { _coordinates[0].M = value; }
        }



        #endregion



        #region Geometry成员

        /// <summary>
        /// 几何类型
        /// </summary>
        public override GeometryType GeometryType
        {
            get { return GeometryType.Point; }
        }

        IList<Coordinate> _coordinates;
        
        /// <summary>
        /// 坐标集合。
        /// </summary>
        public override IList<Coordinate> Coordinates
        {
            get
            {               
                return _coordinates;
            }
            set
            {
               _coordinates=value;
            }
        }

        /// <summary>
        /// 是否为空。
        /// </summary>
        public override bool IsEmpty
        {
            get { return _coordinates == null || _coordinates.Count == 0; }
        }

        /// <summary>
        /// 是否为简单图形。
        /// </summary>
        public override bool IsSimple
        {
            get { return true; }
        }


        /// <summary>
        /// 
        /// </summary>
        public override int Dimension
        {
            get
            {
                return Coordinate.Dimension;
            }           
        }
              

        #endregion

       
        #region SQL

        /// <summary>
        /// 获取WKT描述.
        /// </summary>
        /// <returns></returns>
        public override string AsText()
        {
            return "POINT ( " + Coordinate.X + " " + Coordinate.Y + " )";
        }

        /// <summary>
        /// 获取WKB描述.
        /// </summary>
        /// <returns></returns>
        public override byte[] AsBinarry()
        {
            throw new NotImplementedException();
        }

        #endregion


    }
}
